<html>
<head><meta charset="utf-8"><title>Heuristic for checking if a trait can be derived? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Heuristic.20for.20checking.20if.20a.20trait.20can.20be.20derived.3F.html">Heuristic for checking if a trait can be derived?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="187421322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Heuristic%20for%20checking%20if%20a%20trait%20can%20be%20derived%3F/near/187421322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Andy Russell <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Heuristic.20for.20checking.20if.20a.20trait.20can.20be.20derived.3F.html#187421322">(Feb 05 2020 at 02:57)</a>:</h4>
<p>I'd like to add a structured suggestion to derive <code>Debug</code> if possible on a lint, but I'd prefer to not emit the suggestion if the <code>derive</code> woudn't work. Is there a way to check if the derive is possible? It's fine if there are false positives in more complex cases.</p>



<a name="187421374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Heuristic%20for%20checking%20if%20a%20trait%20can%20be%20derived%3F/near/187421374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Heuristic.20for.20checking.20if.20a.20trait.20can.20be.20derived.3F.html#187421374">(Feb 05 2020 at 02:58)</a>:</h4>
<p>That sounds like something that chalk is able to do</p>



<a name="187421376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Heuristic%20for%20checking%20if%20a%20trait%20can%20be%20derived%3F/near/187421376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Heuristic.20for.20checking.20if.20a.20trait.20can.20be.20derived.3F.html#187421376">(Feb 05 2020 at 02:58)</a>:</h4>
<p>but I have no idea to be honest</p>



<a name="187430901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Heuristic%20for%20checking%20if%20a%20trait%20can%20be%20derived%3F/near/187430901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Heuristic.20for.20checking.20if.20a.20trait.20can.20be.20derived.3F.html#187430901">(Feb 05 2020 at 07:14)</a>:</h4>
<p>Debug can be derived if all fields implement <code>Debug</code>, so you should be able to check that</p>



<a name="187431121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Heuristic%20for%20checking%20if%20a%20trait%20can%20be%20derived%3F/near/187431121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Heuristic.20for.20checking.20if.20a.20trait.20can.20be.20derived.3F.html#187431121">(Feb 05 2020 at 07:20)</a>:</h4>
<p>You could also check it recursively, adding <code>Debug</code> for nested types. You can't derive debug for types from other crates though</p>



<a name="187979339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Heuristic%20for%20checking%20if%20a%20trait%20can%20be%20derived%3F/near/187979339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Andy Russell <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Heuristic.20for.20checking.20if.20a.20trait.20can.20be.20derived.3F.html#187979339">(Feb 12 2020 at 03:44)</a>:</h4>
<p>I understand conceptually that I can do that, but how would I do that within a lint?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>